/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sgt.supermarket.hibernatedao;

import java.util.List;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import sgt.supermarket.entity.ProductBlock;

/**
 *
 * @author Administrator
 */
public class HibernateProductBlockDAO extends HibernateGenericDAO<ProductBlock, Long> {

    public HibernateProductBlockDAO(Session session) {
        super(session);
    }

    public List<ProductBlock> getAvailablesByProductId(long autoId) {
        return getSession()
                .createCriteria(ProductBlock.class)
                .add(Expression.and(Expression.eq("product.autoId", autoId), Expression.ge("availableUnits", new Double(0))))
                .addOrder(Order.asc("purchasedDate"))
                .list();
    }
}
